<template>
  <div class="user-center" v-no-result:[noResultText]="noResult">
    <div class="back" @click="back">
      <i class="icon-back"></i>
    </div>
    <div class="switch-wrapper">
      <Switches :items="['我喜欢的', '最近播放']" v-model="currentIndex"></Switches>
    </div>
    <div class="play-btn" @click="random">
      <i class="icon-play"></i>
      <span class="text">随机播放全部</span>
    </div>
    <div class="list-wrapper">
      <Scroll class="list-scroll" v-if="currentIndex === 0">
        <div class="list-inner">
          <SongList :songs="favoriteList" @select="selectSong"></SongList>
        </div>
      </Scroll>
      <Scroll class="list-scroll" v-if="currentIndex === 1">
        <div class="list-inner">
          <SongList :songs="playHistory" @select="selectSong"></SongList>
        </div>
      </Scroll>
    </div>
  </div>
</template>
<script>
import Scroll from '@/components/base/scroll/scroll.vue'
import SongList from '@/components/base/song-list/song-list.vue'
import Switches from '@/components/base/switch/switch.vue'
import { mapState, mapActions } from 'vuex'
export default {
  name: 'UserCenter',
  components: {
    Scroll,
    SongList,
    Switches
  },
  data () {
    return {
      currentIndex: 0
    }
  },
  computed: {
    noResult () {
      return this.currentIndex === 0 ? !this.favoriteList.length : !this.playHistory.length
    },
    noResultText () {
      return this.currentIndex === 0 ? '快去收藏你喜欢的歌曲吧！' : '快去欣赏你喜欢的歌曲吧！'
    },
    currentList () {
      return this.currentIndex === 0 ? this.favoriteList : this.playHistory
    },
    ...mapState(['favoriteList', 'playHistory'])
  },
  methods: {
    back () {
      this.$router.back()
    },
    selectSong ({ song }) {
      this.addSong(song)
    },
    random () {
      this.randomPlay(this.currentList)
    },
    ...mapActions(['addSong', 'randomPlay'])
  }
}
</script>
<style lang="scss" scoped>
.user-center {
  position: fixed;
  top: 0;
  bottom: 0;
  z-index: 100;
  width: 100%;
  background: $color-background;
  .back {
    position: absolute;
    top: 0.3rem;
    left: 0.255864rem;
    z-index: 50;
    .icon-back {
      display: block;
      padding: 0.426439rem;
      font-size: $font-size-large-x;
      color: $color-theme;
    }
  }
  .switches-wrapper {
    margin: 0.626439rem 0 1.279318rem 0;
  }
  .play-btn {
    box-sizing: border-box;
    width: 5.75693rem;
    padding: 0.298507rem 0;
    margin: 0 auto;
    text-align: center;
    border: 0.042644rem solid $color-theme-d;
    color: $color-theme-d;
    border-radius: 4.264392rem;
    font-size: 0;
    .icon-play {
      display: inline-block;
      vertical-align: middle;
      margin-right: 0.255864rem;
      font-size: $font-size-medium-x;
    }
    .text {
      display: inline-block;
      vertical-align: middle;
      font-size: $font-size-small;
    }
  }
  .list-wrapper {
    position: absolute;
    top: 4.690832rem;
    bottom: 0;
    width: 100%;
    .list-scroll {
      height: 100%;
      overflow: hidden;
      .list-inner {
        padding: 0.852878rem 1.279318rem;
      }
    }
  }
}
</style>
